package com.jingdianjichi.wx.handler;

import com.jingdianjichi.wx.enums.WxMsgTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class SubscribeMsgHandler implements WxChatMsgHandler {
    private static final Logger log = LoggerFactory.getLogger(SubscribeMsgHandler.class);

    @Override
    public WxMsgTypeEnum getMsgTypeEnum() {
        return WxMsgTypeEnum.SUBSCRIBE;
    }

    @Override
    public String dealMsg(Map<String, String> messageMap) {
        log.info("触发用户关注事件");

        String UserName = messageMap.get("FromUserName");
        String adminName = messageMap.get("ToUserName");

        String content = "感谢您的关注，欢迎来到程序员club社区学习";

        String backMsg = "<xml>\n" +
                "  <ToUserName><![CDATA[" + UserName + "]]></ToUserName>\n" +
                "  <FromUserName><![CDATA[" + adminName + "]]></FromUserName>\n" +
                "  <CreateTime>12345678</CreateTime>\n" +
                "  <MsgType><![CDATA[text]]></MsgType>\n" +
                "  <Content><![CDATA[" + content + "]]></Content>\n" +
                "</xml>";
        return backMsg;
    }
}
